package com.xcity.game.item.drop.impl;

import com.xcity.db.entity.Player;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.item.drop.RangeDrop;
import com.xcity.game.item.drop.listener.DropListener;
import com.xcity.game.item.drop.listener.GoldDropListener;

import naga.x.util.CommonUtils;

public class GoldDrop extends RangeDrop {

	public GoldDrop(int gold) {
		this(GameStaticConfig.defaultChanceBase, 0, gold);
	}
	
	public GoldDrop(int probability, int weight, int gold) {
		this(probability, weight, gold, gold);
	}
	
	public GoldDrop(int probability, int weight, int minGold, int maxGold) {
		this.probability = probability;
		this.weight = weight;
		this.min = minGold;
		this.max = maxGold;
	}

	@Override
	protected void processDrop(Player player, String cause, DropListener listener) {
		int gold = CommonUtils.randomInt(RND, min, max);
		if (gold <= 0) {
			return;
		}
		if (player != null) {
			player.addGold(gold, cause);
		}
		if (listener != null && listener instanceof GoldDropListener) {
			((GoldDropListener) listener).goldDroped(player, gold);
		}
	}

	public int getGold() {
		return max;
	}

}
